package org.grow.auth.controller;

import org.grow.auth.dao.MenuMapper;
import org.grow.auth.dao.UltraInfoMapper;
import org.grow.auth.domain.Menu;
import org.grow.auth.domain.UltraInfo;
import org.grow.auth.service.UltraInfoService;
import org.grow.common.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2023/9/22
 */

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuMapper menuMapper;

    @GetMapping("/findAll")
    public List<Menu> findAll() {
        return menuMapper.findAll();
    }

    @Autowired
    private UltraInfoService ultraInfoService;

    @GetMapping("/findByOfficialName")
    public List<Menu> findByOfficialName() {
        String currentUser = AuthInterceptor.getCurrentUser();
        UltraInfo ultraInfo = ultraInfoService.findByOfficialName(currentUser);
        String menus = ultraInfo.getMenus();
        String[] menuArray = (menus.split(","));
        return menuMapper.findInMenuIds(menuArray);
    }

}
